<!-- 数据主体 -->

<?php if(!IS_AJAX){?>

<div class="row" style="height:1000px; margin:0;">
    <?php if(!isset($_GET['selected'])){?>
    <div class="col-sm-4">
        <div class="panel">
            <div class="panel-body">
                <html:dropdownselect class="typeselect" selected="" name="type" style="height:auto; width:auto;" multi="0" action="{:U('Team/tree')}" title="选择规则"  placeholder="点击选择规则"  listloaded="listloaded" />
                <style>
                    .selectlist{margin:0; padding:0;}
                    .selectlist li{list-style-type:none; margin:0; padding:0;padding:5px; border-bottom:1px solid #eee; margin:0 8px;}
                    .selectlist li:hover{background:#eee;}
                </style>
                <div id="reselectlayout" style="top:0; display:none; left:0; bottom:0; right:0; position:fixed; z-index:4999;"></div>
            </div>
        </div>
        <form action="<?php echo U('select');?>" method="post" id="selectdatalistform">
            <div class="input-group m-bot15 hidden">
                <input type="text" name="keywords" class="form-control">
                <span class="input-group-btn">
                <button type="submit" class="btn btn-default"><i class="fa icon-search" style="font-size:16px"></i></button>
                </span>
            </div>
        </form>
    </div>
    <div class="col-sm-8">
        <div id="selectdatalist" class="">
            <?php }?>
            <?php }?>
            <?php if(IS_AJAX){?>
            <volist name="list" id="vo">
                <?php if(!isset($_GET['selected'])){?>
                <div class="SelectDataListItem widget-container fluid-height labe item<?php echo($vo['id']); ?>" style="margin-top:4px; padding:0 5px;">
                    <div class="heading">
                        <i class="fa icon-check-circle"></i><i class="fa icon-circle-o"></i> <?php echo($vo['name']); ?> <span class="text-success pull-right"><?php echo($vo['integralnum']); ?></span>
                    </div>
                    <div class="widget-content padded">
                        <p>备注：<?php echo($vo['remark']); ?></p>
                    </div>
                    <div class="DataBox hidden">
                        <?php }?>
                        <!-- 选中的数据主体 -->
                        <div style="position:relative;" class="label-success pull-left label btn label-rule">
                            <input type="hidden" name="id<?php if(count($list) > 1 && isset($_GET['selected'])){echo '[]';}?>" value="{$vo.id}">
                            <input type="hidden" value="{$vo.name}" name="name<?php if(count($list) > 1 && isset($_GET['selected'])){echo '[]';}?>">
                            {$vo.name}<span class="">&nbsp;{$vo.integralnum}</span>
                            <a href="javascript:void(0);" onClick="$(this).parent().remove();" style="position:absolute; border-radius:20px; font-size:20px; font-weight:bold; top:0; right:0; background:#f00; display:block; width:20px; height:20px; line-height:20px; text-align:center; color:#fff;z-index:2;">
                                -
                            </a>
                        </div>
                        <!-- 选中的数据主体结束-->
                        <?php if(!isset($_GET['selected'])){?>
                    </div>
                    <div class="hidden sourceList" data-source="item<?php echo($vo['id']); ?>">
                    	<?php
                        	//判断是否有设置详细积分源，如有则加入积分框，无则无
                            $source='';
                            $inte='';
                        	if(!empty($vo['source'])){
                            	$data=unserialize($vo['source']);
                                foreach($data as $k=>$v){
                                	if(!empty($v[0])){
                                        $inte.='<li>'.$integralType[$k].'： '.$v[0];
                                        if(!empty($v[1])){
                                            $remark='请输入'.$v[0].'至'.$v[1].'之间的'.$k;
                                            $source.='<div style="min-width:110px;"><label title="'.$remark.'">'.$k.'： </label><input class="sourceInput" min="'.$v[0].'" max="'.$v[1].'" maxlength="5" type="number" title="'.$remark.'" name="'.$k.'" value="'.$v[0].'"/></div>';
                                            $inte.='至'.$v[1];
                                        }
                                        $inte.='</li>';
                                    }
                                }
                                if(!empty($inte)){
                                    $source='<div class="sourcePanel">'.$source.'</div>';
                                    $inte='<ul class="intePanel list-unstyled">'.$inte.'</ul>';
                                }
                            };
                        
                            $html='<label data-target="item'.$vo['id'].'" class="checkbox-inline radio-inline item item'.$vo['id'].'">'.$inte.'<input type="hidden" name="" class="checkbox" value="'.$vo['id'].'"/><div class="checkbox  single-row square-red"><label><input type="checkbox" class="item'.$vo['id'].'" value="" name="1">'.$vo['name'].'</label></div><i class="fa faicon icon-times" title="删除块"></i></label>';
                            echo($html);
            			?>
                    </div>
                </div>
                <?php }?>
            </volist>
            <?php }?>
            <?php if(!IS_AJAX){?>
            <?php if(!isset($_GET['selected'])){?>
        </div>
        <div style="text-align:center;" id="selectdatalistpages">
        </div>
    </div>
    <?php }?>
</div>
<div class="panel panel-rightMenu">
    <ul class="list-unstyled">
        <li class="treeEdit" rel="<?php echo U('Integral_ruletype/edit'); ?>">修改分类</li>
        <li class="treeAdd" rel="<?php echo U('Integral_ruletype/addChild'); ?>">添加子集</li>
        <li class="treeDelete" rel="<?php echo U('Integral_ruletype/delete'); ?>">删除</li>
    </ul>
</div>
<style>
    .panel-rightMenu{ box-shadow:4px 4px 5px rgba(0,0,0,0.2); border:1px solid #ddd; border-radius:2px;position: fixed;width: 250px; z-index:999; color:#333; display:none;}
    .panel-rightMenu li{ padding-left:20px; padding-top:6px; padding-bottom:6px; font-size:12px;}
    .panel-rightMenu li:hover{ background:#eee; cursor:pointer;}
</style>
<script>
	//选择员工的加载
    function listloaded(){
        $('.typeselect').blur(function(){
            $("#selectdatalistform input[name='type_id']").remove();
            if($('.typeselect .itemspan').children('input:eq(1)').length!=0){
                $('#selectdatalistform').append("<input type='hidden' name='type_id' value='"+$('.typeselect .itemspan').children("input:eq(1)").attr('value')+"'>");
            }
            $('#selectdatalistform').submit();
        });
    }
	
	//当鼠标离开菜单的时候 移除样式
	$(".panel-rightMenu").mouseleave(function(e) {
        $(this).removeAttr("style");
    });
	var settingbefore = {
        view: {
            selectedMulti: false,
			addDiyDom:addDiyDom
        },
        async: {
            enable: true,
            url:"{:U('Integral_ruletype/ruletypeTree')}",
            autoParam:["id", "name=n", "level=lv"],
            otherParam:{"otherParam":"zTreeAsyncTest"},
            dataFilter: fillup
        },
        callback: {
            beforeClick: Clickbefore,
            beforeAsync: Asyncbefore,
			onRightClick:onRightClick,
            onAsyncError: ErroronAsync,
            onAsyncSuccess: SuccessonAsync
        }
    };
    function fillup(treeId, parentNode, childNodes) {
        if (!childNodes) return null;
        for (var i=0, l=childNodes.length; i<l; i++) {
            childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
        }
        return childNodes;
    }
	//当右键点击的时候，显示菜单和邦定相应的事件
	function onRightClick(treeId,treeNode){
		var dataId=$(treeId.target).find(".treeData").attr('data-id');
		var dataTId=$(treeId.target).find(".treeData").attr('data-tid');
		var nodes = treeObj.getNodeByTId(dataTId).getParentNode();
		var pNodes=nodes?nodes.getParentNode():nodes;
		var span=$("#"+dataTId+"_span");
		
		$(".panel-rightMenu").css({'left':treeId.clientX*1-4,'top':treeId.clientY*1-4,'display':'block'});
		$(".panel-rightMenu .treeAdd").unbind("click");
		$(".panel-rightMenu .treeEdit").unbind("click");
		//当点击‘添加子集’的时候
		$(".panel-rightMenu .treeAdd").click(function(e) {
			var url=$(this).attr('rel')+'&id='+dataId;
			//弹出窗口
            _openWindow(url,650,'新建积分规则分类','提交',function(){
				//刷新修改了的节点
				treeObj.reAsyncChildNodes(nodes, "refresh",'false');
			});
        });
		//当点击‘修改分类’的时候
		$(".panel-rightMenu .treeEdit").click(function(e) {
			var url=$(this).attr('rel')+'&id='+dataId;
			//弹出窗口
            _openWindow(url,650,'修改积分规则分类','提',function(){
				//获取修改后的数据
				$.getJSON('{:U('Integral_ruletype/getInfo')}',{id:dataId},function(data){
					var pNodes2=treeObj.getNodesByParam('id',data.info['pid'],null)[0];
					pNodes2=pNodes2['getParentNode']?pNodes2.getParentNode():pNodes2;
					//刷新修改前的父节点和修改后的父节点
					treeObj.reAsyncChildNodes(pNodes2,"refresh",'false');
					if(pNodes!=pNodes2){
						treeObj.reAsyncChildNodes(pNodes, "refresh");
					}
				});
			});
        });
		//当点击‘删除’的时候
		$(".panel-rightMenu .treeDelete").click(function(e) {
			var url=$(this).attr('rel');
            $.getJSON(url,{'id':dataId},function(data){
				if(data.statu==0){
					artDialog({content:data.info})
				}else{
					treeObj.reAsyncChildNodes(nodes, "refresh",'false');
				}
			});
        });
	}
	function addDiyDom(treeId,treeNode){
		$("<i>").addClass("treeData").attr({'data-id':treeNode.id,'data-tId':treeNode.tId}).appendTo($('#'+treeNode.tId+'_span'));
	}
    function Clickbefore(treeId, treeNode) {
        var html = '<div id="member_pos_id'+treeNode.id+'" class="alert member_pos_id alert-info fade in" style="display:inline-block; margin-bottom:2px; margin-right:2px; padding:5px;"><button type="button" class="close close-sm" onclick="$(this).parent().remove();$(\'#ajaxlistboxform\').submit();" data-dismiss="alert"> <i class="fa icon-times"></i> </button><strong><input type="hidden" value="'+treeNode.id+'" name="type_id" class="NodeId" />'+treeNode.name+'</strong> </div>';
        $('.member_pos_id').remove();
        $(html).appendTo('.membertreebox');
        $('#selectdatalistform').submit();
        if (!treeNode.isParent) {
            return false;
        } else {
            return true;
        }
    }
   var className = "dark";
    function Asyncbefore(treeId, treeNode) {
        className = (className === "dark" ? "":"dark");
        return true;
    }
    function ErroronAsync(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) { }
    function SuccessonAsync(event, treeId, treeNode, msg) { }
	$(window).trigger("load");
   //$.fn.zTree.init($("#membertree"), settingbefore);
   //var treeObj = $.fn.zTree.getZTreeObj("membertree");
</script>
<?php }?>
